/**
 * everything soud manager related
 */
 /*
var soundManager = new SoundManager();
soundManager.onload = function() {
   soundManager.createSound({id: 'msg_in', url: 'sounds/msg_in.mp3', autoLoad: true});
   soundManager.createSound({id: 'msg_out', url: 'sounds/msg_out.mp3', autoLoad: true});
   soundManager.play('msg_out');
};
soundManager.debugMode = true;
soundManager.onload();
soundManager.beginDelayedInit();

// attach event
//  before window is unloaded, remove sound manager
Element.observe(window, 'beforeunload', soundManager.destruct);
*/

/**
 * Wrapper to scroll down within an element
 *
 * @arguments
 *   id - element to scroll down within
 *
 * @author Joshua Gross
 **/
function scrollToBottom(id) {
   $(id).scrollTop = $(id).scrollHeight - $(id).clientHeight;
}

/**
 * Strip out whitespace on then sides of 'text'
 *
 * @author Joshua Gross
 * @return trimmed 'text'
 **/
function trim(text) {
   if(text == null) return null;
   return text.replace(/^[ \t]+|[ \t]+$/g, "");
}
   
function createTimestamp() {
      Stamp = new Date();
      var tH = String(Stamp.getHours()); var ti = String(Stamp.getMinutes()); var ts = String(Stamp.getSeconds());
      var th = tH > 12 ? tH - 12 : tH; var ta = tH > 12 ? 'pm' : 'am'; var tA = tH > 12 ? 'PM' : 'AM';
      var td = String(Stamp.getDate()); var tm = String(Stamp.getMonth() + 1);
      var tM = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'July', 'Aug', 'Sep', 'Nov', 'Dec'][tm - 1];
      var tY = String(Stamp.getFullYear()); var ty = tY.substring(2);
      
      tu = tm; tx = td; tQ = tH;
      
      tH = (tH.length > 1) ? tH : "0"+tH; ti = (ti.length > 1) ? ti : "0"+ti;
      tq = (th.length > 1) ? th : "0"+th; ts = (ts.length > 1) ? ts : "0"+ts;
      td = (td.length > 1) ? td : "0"+td; tm = (tm.length > 1) ? tm : "0"+tm;
      
       /* PROVISOIRE */
      var timestamp = '[h:i:s a]';
      if(typeof timestamp == 'undefined') {
         timestamp = self.opener.timestamp;
      }
      return timestamp.replace(/H/, tH).replace(/h/, th).replace(/i/, ti).replace(/s/, ts)
                          .replace(/d/, td).replace(/Y/, tY).replace(/y/, ty).replace(/m/, tm)
                          .replace(/u/, tu).replace(/x/, tx).replace(/Q/, tQ).replace(/q/, tq)
                          .replace(/a/, ta).replace(/A/, tA).replace(/M/, tM);
}


/**
 * Button effects for browsers without ":" support
 *
 * @arguments
 *   el - element to affect
 *
 * @author Joshua Gross
 **/
function buttonHover(el) {
   var newsrc = el.src;
   newsrc = newsrc.replace(/_hover/, '');
   el.src = newsrc.replace(/\.png/, '_hover.png');
}
function buttonDown(el) {
   el.src = el.src.replace(/_hover\.png/, '_down.png');
}
function buttonNormal(el) {
   el.src = el.src.replace(/\_hover.png/, '.png').replace(/\_down.png/, '.png');
}

/**
 * Will run through passed variable 'text' and fix
 * it's regExpression faults.
 *
 * @author Joshua Gross
 * @return formatted 'text'
 **/
function regExpEscape(text) {
  if (!arguments.callee.sRE) {
    var specials = [
      '/', '.', '*', '+', '?', '|',
      '(', ')', '[', ']', '{', '}', '\\'
    ];
    arguments.callee.sRE = new RegExp(
      '(\\' + specials.join('|\\') + ')', 'g'
    );
  }
  return text.replace(arguments.callee.sRE, '\\$1');
}

/** ESSAI
*/
function TB_load_position() {
	if ($(loadingid)) { $(loadingid).setStyles({left: (window.getScrollLeft() + (window.getWidth() - 56)/2)+'px', top: (window.getScrollTop() + ((window.getHeight()-20)/2))+'px',display:"block"}); }
}
  


